package com.xbh.management.security;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.security.authentication.AuthenticationDetailsSource;
import org.springframework.security.web.authentication.WebAuthenticationDetails;
import org.springframework.stereotype.Component;

import javax.servlet.http.HttpServletRequest;

/**
 * @program: management-center
 * @description: 替换SpringSecurity原生的WebAuthenticationDetails
 * 自定义了WebAuthenticationDetails，我i们还需要将其放入 AuthenticationDetailsSource
 * 中来替换原本的 WebAuthenticationDetails ，因此还得实现自定义 AuthenticationDetailsSource
 * 注意坑点！！！SpringSecurity默认不支持json格式的数据
 * @author: 许宝华
 * @create: 2021-10-07 18:13
 */


@Component("authenticationDetailsSource")

public class UserAuthenticationDetailsSource implements AuthenticationDetailsSource<HttpServletRequest, WebAuthenticationDetails> {

    private static Logger log = LoggerFactory.getLogger(UserAuthenticationDetailsSource.class);

    @Override
    public WebAuthenticationDetails buildDetails(HttpServletRequest request) {
        log.info("开始替换SpringSecurity原生的WebAuthenticationDetails");
        return new UserWebAuthenticationDetails(request);
    }
}
